package cn.edu.cuc.yjsy.admin.connection;

import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class SourceConnection extends AbstractConnection {
	
	private String dbUrl;
	
	public SourceConnection(String path){
		super("sourcedb.xml");
		
		dbUrl = db.getUrl() + path;
	}
	
	public SourceConnection(String path, String table){
		this(path);
		tableName = table;
	}

	public void connection() throws SQLException {
		conn = DriverManager.getConnection(dbUrl);
	}

	public String[] getTables() throws SQLException{
		List tables = new ArrayList();
		ResultSet rs = null;
		try{
			DatabaseMetaData metaData = conn.getMetaData();

			rs = metaData.getTables(null, null, "%", null);
			while(rs.next())
				tables.add(rs.getString("TABLE_NAME"));
		}finally{
			if(rs != null)
				rs.close();
		}
		
		return (String[])tables.toArray(new String[0]);
	}
}
